# import cv2
#
# image = cv2.imread('./scene/a.png')
#
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#
# _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
#
# import pytesseract
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
#
# custom_config = r'--psm 6'
# data = pytesseract.image_to_data(thresh, config=custom_config, lang='chi_sim')
#
# for i, line in enumerate(data.splitlines()):
#     if i == 0:
#         continue
#     info = line.split()
#     if len(info) == 12:
#         x, y, w, h = map(int, info[6:10])
#         text = info[11]
#         print(text)
#         # if (text == '混和'):
#
#         cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
#         # cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
#
#
# cv2.imshow('Image', image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
import cv2
import numpy as np
import mss

import action

from paddleocr import PaddleOCR, draw_ocr

# Paddleocr supports Chinese, English, French, German, Korean and Japanese
# You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan`
# to switch the language model in order
ocr = PaddleOCR(use_angle_cls=True) # need to run only once to download and load model into memory
img_path = './scene/t1.png'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

# draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
print(boxes, txts, scores)